<?php

namespace app\common\service;

/**
 * 题目类型服务
 */
class QuestionTypeService
{
    /**
     * getType
     * @param $question
     * @return int
     */
    public static function getType($question): int
    {
        // 题目类型
        $questionType = 4;

        // 是否判断题
        if (isset($question['A']) && isset($question['B']) && $question['A'] == '正确' && $question['B'] == '错误') {
            return 3;
        }

        // 判断是否选择题
        $allSelect = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'];
        foreach ($allSelect as $select) {
            if (isset($question[$select])) {
                $questionType = 0;
                break;
            }
        }
        if ($questionType !== 0) {
            return $questionType;
        }

        // 检查是单选还是多选
        return strlen($question['correctOption']) == 1 ? 1 : 2;
    }
}